package Servlet;

import dao.Impl.ProductImpl;
import dao.ProductDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * ClossName:DeleProductServlet
 * Pakage:Servlet
 * Description
 *
 * @Author L
 * @Create 2023/10/31 16:30
 * @Version 2023.1.3
 */
@WebServlet("/dele.product")
public class DeleProductServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setCharacterEncoding("utf-8");

        PrintWriter out = resp.getWriter();

        //获取客户端传来的数据
        String id = req.getParameter("id");
        Integer a = Integer.valueOf(id);
        System.out.println(a);
        //调用方法
        ProductDao productDao = new ProductImpl();
        int rows = productDao.deleteProduct(a);

        if (rows > 0){
            out.println("删除成功!");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
